var app=new Vue({
    el: '#app',
    data:{
        helpList: null,
        searchHelp:{
            total:0,
            pageSize:10,
            pageIndex:1,
            startEndDate: ""
        },
        dicts:{
            type: [],
            status: []
        }
    },
    methods:{
        init: function(){
            var _this=this;
            setTimeout(function(){
                _this.findAll();
                _this.initDict();
            },100);
        },
        updateStatus: function(row,value){
            var _this=this;
            jsmile.http.sendJson({
                url:jsmile.url+"/sys/help/enable",
                data:{"id":row.id,"enable":value}
            }).done(function(res){
                jsmile.msg.success("修改文档状态成功!");
                _this.query();
            }).fail(function(res){
                jsmile.msg.error(res.resMsg?res.resMsg:"修改文档状态失败!");
            });
        },
        addHelp: function(){
            top.layer.open(jsmile.dialog.init({
                title: "新增文档",
                content: "doc/help/add.html"
            }));
        },
        editHelp: function(index,row){
            var _this=this;
            top.layer.open(jsmile.dialog.init({
                title: "修改文档信息",
                content: "doc/help/edit.html",
                success: function(layero,index){
                    var iframeW=layero.find('iframe')[0];
                    setTimeout(function(){
                        iframeW.contentWindow.app.help=row;
                        iframeW.contentWindow.app.ue.setContent(row.hContent);
                    },100);
                }
            }));
        },
        deleteHelp: function(index,row){
            var _this=this;
            top.app.$confirm('此操作将永久删除该文档, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(function() {
                jsmile.http.sendJson({
                    url:jsmile.url+"/sys/help/delete",
                    data:{"id":row.id}
                }).done(function(res){
                    jsmile.msg.success("删除文档成功!");
                    _this.query();
                }).fail(function(res){
                    jsmile.msg.error(res.resMsg?res.resMsg:"删除文档失败!");
                });
            }).catch(function(){
                jsmile.msg.info( '已取消删除');
            });
        },
        query: function(){
            this.searchHelp.pageIndex=1;
            this.findAll();
        },
        /**
         * 初始化数据字典
         */
        initDict: function(){
            var _this=this;
            var s=jsmile.copy([],jsmile.dict.zt);
            s.unshift({dictName:"全部",dictValue:null});
            _this.dicts.status=s;

            jsmile.http.sendJson({
                url:jsmile.url+"/sys/dict/findDictByCode",
                data:{"dictCode":"DH01"}
            }).done(function(res){
                res.resData.splice(0,0,{dictName:"全部",dictValue:null});
                _this.dicts.type=res.resData;
            });
        },
        goHome: function(url){
            top.$('#home').attr("src","homePage/home.html");
        },
        handleSizeChange: function(val) {
            this.searchHelp.pageSize=val;
            this.findAll();
        },
        handleCurrentChange: function(val) {
            this.searchHelp.pageIndex=val;
            this.findAll();
        },
        /*
         * 获取所有数据
         */
        findAll: function(){
            if(!this.searchHelp.startEndDate){
                this.searchHelp.startEndDate="";
            }else{
                this.searchHelp.startDate=this.searchHelp.startEndDate[0];
                this.searchHelp.endDate=this.searchHelp.startEndDate[1];
            }

            var _this=this;
            jsmile.http.sendJson({
                url:jsmile.url+"/sys/help/findAll",
                data:_this.searchHelp
            }).done(function(res){
                _this.helpList=res.resData.list;
                _this.searchHelp.total=res.resData.total;
            }).fail(function(res){
                jsmile.msg.error(res.resMsg?res.resMsg:"获取文档列表失败!");
            });
        }
    }
});
$(function(){
    init();
    function init(){
        app.init();
    }
});